package com.jt.common.interceptor;

import com.sun.corba.se.spi.activation.Server;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

interface HandlerInterceptor1{
    default  void asdasd(){};
    default  void qweqwe(){};
}
interface Handler1{
    void yuiyiu();
}
class HandlerChain1{
    private List<HandlerInterceptor1> interceptors1=new CopyOnWriteArrayList<>();
    private Handler1 handler1;

    public HandlerChain1(List<HandlerInterceptor1> interceptors1, Handler1 handler1) {
        this.interceptors1.addAll(interceptors1);
        this.handler1 = handler1;
    }
    public  void ExecutionChain1(){
        for (int i = 0; i <interceptors1.size() ; i++) {
            interceptors1.get(i).asdasd();
        }
        handler1.yuiyiu();

        for (int i =interceptors1.size()-1; i >=0; i--) {
            interceptors1.get(i).qweqwe();
        }
    }

}

public class XieBuRouFramework {
    public static void main(String[] args) {
        List<HandlerInterceptor1> handlerInterceptor1List=new CopyOnWriteArrayList<>();
        HandlerInterceptor1 hi1=new HandlerInterceptor1() {
            @Override
            public void asdasd() {
                System.out.println("蟹不肉1");
            }

            @Override
            public void qweqwe() {
                System.out.println("蟹不肉2");
            }
        };

        Handler1 h=new Handler1() {
            @Override
            public void yuiyiu() {
                System.out.println("蟹不肉本肉");
            }
        };
        handlerInterceptor1List.add(hi1);
        HandlerChain1 hc1=new HandlerChain1(handlerInterceptor1List, h);
        hc1.ExecutionChain1();
    }

}
